// handleQuery.js

import axios from "axios";
import dayjs from "dayjs";
import { ElMessage, ElMessageBox, ElNotification } from "element-plus";

export default function (startTime = null, endTime = null) {
  const startTimeString = startTime
    ? dayjs(startTime).format("YYYY-MM-DD HH:mm:ss")
    : dayjs().subtract(2, "hour").format("YYYY-MM-DD HH:mm:ss");

  const endTimeString = endTime
    ? dayjs(endTime).format("YYYY-MM-DD HH:mm:ss")
    : dayjs().format("YYYY-MM-DD HH:mm:ss");

  return new Promise((resolve, reject) => {
    axios
      .post("api/journal_diversion_share.php", {
        action: "query",
        data: {
          startTime: startTimeString,
          endTime: endTimeString,
        },
      })
      .then((response) => {
        if (response.data.result) {
          resolve(response.data.result);
        } else {
          reject(response.data);
        }
      })
      .catch((error) => {
        reject(error);
      });
  });
}
